
$(
    getData()

)


let obj={}


function query() {

    let keyword = $('#keyword').val()


    obj={

        keyword

    }


    Data('get',obj)
    
}


function del(id) {

    obj={

        id

    }

if (confirm(`是否要删除id为${id}的数据`)) {
    

    Data('delete',obj)

}


    
}




function edit(id) {
  
    location.href=`./E_A.html?${id}`

}

function add() {
  
    location.href=`./E_A.html`

}




function Data(type,data) {

    let url=`http://localhost:3000/product`

    let success=data=>{

        location.href='index.html'

        getData(data)

    }


    if (type=='get') {
        
        url=`http://localhost:3000/product/${data.keyword}`

        success=data=>getData(data)

    }


    $.ajax({

        url,

        type,

        data,

        success

    })


}








function getData(newData) {
    
    $('.tr').remove();

    $.get('http://localhost:3000/product',data=>{

    if (newData) {

        data=newData

    }


    data.forEach(item => {
        
        let html =`
        

        <tr class='tr'>
            <td>
                ${item.id}
            </td>
            <td>
            ${item.Title }
            </td>
            <td>
            ${item.Digest  }
            </td>
            <td>
            ${item.Content }
            </td>
            <td>
            ${item.Classify  }
            </td>
            <td>
            ${item.Author }
            </td>
            <td>
            ${item.Time}
            </td>
            <td>
                <input type="button" value="修改" onclick="edit( ${item.id})">
                <input type="button" value="删除" onclick="del( ${item.id})">
            </td>


        </tr>

        `

        $('#tb').append(html);

    });

        




    })






}